<script setup lang="ts">
import { ref } from 'vue'
import ClassTypeTable from './ClassType/ClassTypeTable.vue'
import DictTable from '@/views/develop/dict/DictTable.vue'
import { DictApi } from '@/apis'

defineOptions({
  name: 'BaseInfo',
})
const dictType = ref<DictApi.DictType>('system')
const dictId = ref('TermEnum')

const menuGroups = [
  {
    title: '教务信息',
    children: [
      { title: '学期', code: 'TermEnum', type: 'system' },
      {
        title: '年级',
        code: 'grade',
        type: 'custom',
      },
      {
        title: '科目',
        code: 'subject',
        type: 'custom',
      },
      {
        title: '班级分类',
        code: 'ClassCategoryEnum',
        type: 'system',
      },
      {
        title: '班级类型',
        code: 'ClassType',
        type: undefined,
      },
    ],
  },
  {
    title: '招生信息',
    children: [
      { title: '家长关系', code: 'ParentRelation', type: 'custom' },
      { title: '学生来源', code: 'StudentSource', type: 'custom' },
    ],
  },
]

const onSelect = async (item) => {
  dictType.value = item.type
  if (item.type === 'custom') {
    dictId.value = await DictApi.getDictIdByCode(item.code)
  } else {
    dictId.value = item.code
  }
}
</script>

<template>
  <ProPage title="基础信息" flex-table>
    <a-row align="stretch" class="h-full">
      <a-col :xs="0" :sm="8" :md="7" :lg="6" :xl="5" :xxl="4" flex="180px" class="h-full overflow-hidden">
        <a-menu
          class="menu"
          auto-open-selected
          :default-selected-keys="['TermEnum']"
        >
          <a-sub-menu v-for="(group, index) in menuGroups" :key="index" :title="group.title">
            <a-menu-item v-for="item in group.children" :key="item.code" @click="onSelect(item)">
              {{ item.title }}
            </a-menu-item>
          </a-sub-menu>
        </a-menu>
      </a-col>
      <a-divider direction="vertical" />
      <a-col :xs="24" :sm="16" :md="17" :lg="18" :xl="19" :xxl="20" flex="1" class="h-full overflow-hidden">
        <ClassTypeTable v-if="dictId === 'ClassType'" />
        <DictTable v-else :id="dictId" :type="dictType" />
      </a-col>
    </a-row>
  </ProPage>
</template>

<style lang="less" scoped>
</style>
